﻿<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<title>积分查询</title>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/qmsk-1.2.js"></script>
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/checkLogin.js"></script>
<script type="text/javascript" src="../js/shopSelecterNew.js"></script>
<script type="text/javascript" src="../js/pagination.js"></script>
<script type="text/javascript" src="../js/dataTable.js"></script>
<script type="text/javascript" src="../js/find.js"></script>
<!-- InstanceBeginEditable name="EditRegion3" -->
<script type="text/javascript" src="../js/commonSelecter.js"></script>
<script type="text/javascript" src="../js/doubleDate2.0.js"></script>
<script type="text/javascript">
	/**
	 * 入口，和服务器的通信从此开始
	 */
	 var sum = 0;
	$(function() {
		refreshInput($(".serWrapper"));
		initShopSelecter();
		$('.doubledate').kuiDate({
			className : 'doubledate',
			isDisabled : "1" // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选
		});
		$('.doubledate1').kuiDate({
			className : 'doubledate1',
			isDisabled : "1" // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选
		});
		$("#IntgraAdd").hide();
		$(".memberInfo").attr("disabled", "disabled");
		 $('#startDate').val(getToday());
		 $('#endDate').val(getToday());
		 initSelect();
	});
	
	
	function initSelect(){
		var shopId = $('#shopID').val();
		if(IsEmpty(shopId)){
			$("#shopIsChoosed").removeAttr("checked");
		}
		$('#paid').val();
		$("#memberCardNo").val("")
		$("#mp").val("");
	}
	
	/**
	 * 初始化店面选择器
	 */
	function initShopSelecter() {
		refreshInput($(".serWrapper"));
		$("#shopID").attr("disabled", "disabled");
		$("#shopIsChoosed").bind("click", function() {
			var checked = $(this).attr("checked");
			if (checked) {
				$("#shopID").removeAttr("disabled");
			} else {
				$("#shopID").attr("disabled", "disabled");
				$("#shopID").empty();
			}
		});
	}

	
/* 	'../memberDepositBill/find/shopId/' + shopId + '/params/'
	+ (pageIndex - 1) + '/' + _pageSize */

	/**
	 * 为查找做准备，这里主要是生成查询条件对象
	 */
	function toSearch() {
		sum=0;
		$("#sum").empty();
		$("#membersIntgra").empty();
		var shopId="";
		if($("#shopIsChoosed").is(":checked")){	
			shopId=getHtmlString($("#shopID").val());
		}
		var custName = $('#custName').val();
		var ruleId = $('#selectRule').val();
		var startDate = $('#startDate').val();
		var endDate = $('#endDate').val();
		var paid = $('#paid').val();
		var memberCardNo = $("#memberCardNo").val()
		var mp = $("#mp").val();
		new Pagination({
			url : '../memberIntgra/find/shopId/params/',
			data : {
				shopId : shopId,
				startDate : startDate,
				endDate : endDate,
				paid : paid,
				ruleId :ruleId,
				custName : custName,
				memberCardNo : memberCardNo,
				mp:mp
				},
			success : printDataToPage,
			pageSize : 10
		});
		
	}
	
	/**
	 * 将数据打印到页面
	 */			

	function printDataToPage(message) {
		dataTable({
			tbodyId : 'membersIntgra',
			 heads : ["ShopName", "BillNo", "crFTime", "memberCardNo", "custName", "mp", "RuleName", "IsIntAdjustment","Integral","crFMan","Paid"],
			rst : message,
			sup : {
				id : "sup",
				template : "共 [index] 条"
			},
			handler : [{
				col : 10,
				f : paid
			},{
				col : 8,
				f : Integral
			},{
				col : 7,
				f : IsIntAdjustment
			}],
			trGender:trGenders
		});
		$("#sum").html("积分汇总："+sum);
	}
	
	function Integral(heads, row){
		if(IsNotEmpty(heads)){
			sum=parseInt(sum)+parseInt(heads);
		}
		return "<span>"+heads+"</span>";
	}
	
	function IsIntAdjustment(heads, row){
		var intgraType = "";
		if(IsNotEmpty(heads)){
			if(heads == 1){
				intgraType = "积分调整";
			}else{
				intgraType = "会员积分";				
			}
		}else{
			intgraType = "会员积分"
		}
		return intgraType;
	}
	
	function trGenders(row){
		if(IsNotEmpty(row)){
			return "<tr id='Ids"+row+"' ></tr>";
		}
	}
	
	function paid(heads, row) {
		var paidName = "";
		if(IsNotEmpty(heads)){
			if(heads == 0){
				paidName = "未处理";
			}else{
				paidName = "已处理";				
			}
		}
		return paidName;
	}
	
	/**
	 * 点击充值按钮
	 */
	function toAdd() {
		var shopId =$("#shopID").val()
		if(IsEmpty(shopId)){
			artError("请先选择店铺 ")
			return false
		}else{
			var htm="<option value='"+shopId+"'>"+$("#shopID").text()+"</option>"
			$("#shopID1").html(htm)
		}
		$("#ralRate").hide();
		$("#save_btn").removeAttr("disabled");
		$("#save_btn").removeAttr("style");
		$("#paid_btn").attr("disabled","disabled");
		$("#paid_btn").attr("style","background:#E27F66;");
		$("#IntgraAdd").show();
		$("#IntgraSelect").hide();
		$(".clearValue").val("");
	}
	
	/**
	 * 返回查询界面按钮
	 */
	function toSelect() {
		$("#IntgraAdd").hide();
		$("#IntgraSelect").show();
	}
	

	
	function toDelete(id,row) {
		if (IsEmpty(id)) {
			artError('未获取到主要信息！');
			return false;
		}
		var paid = $("#Ids"+row).find("td:eq(10)").text();
		if(IsNotEmpty(paid)){
			if(paid == "已处理"){
				artError('不能删除已处理的单据');
				return false;
			}
		}
		
		//提示用户 确认删除
		art.dialog({
			'fixed':true,
			'lock':true,
			'title' : '警告',
			'icon':'question',
			'content' : '确定要删除吗？',
			'cancel' : function() {
			},
			'ok' : function() {
				$.post('../memberIntgra/del', {
					'id' : id
				}, function(message) {
					if (IsEmpty(message)) {
						artError("删除出错");
						return false;
					}
					if (message.state == 0) {
						toSearch();
						artSuccess('删除成功');
					} else if (message.state == 1) {
						artError("删除失败");
					} else {
						checkStateShowErrorMsgAndDealResult(message);
					}
				}, 'json');
			}
		}); 
		//直接发出请求
	}
	//选择积分规则
	function selectIntgraRule(){
		$("#selectRule").blur();
		var shopId = $('#shopID').val();
		if(IsEmpty(shopId)){
			art.dialog({fixed:true, lock: true,content:"请选择店面",icon:'error',ok:true});	
			return false;
		}
		initSelecter({
			url : '../memberIntRule/find/opt/',
			heads : ["shopName","name","levelName"],
			titles : ["店名称","规则名称","级别名称"],
			zindex : 500,
			callBack : callBack
		});
	}

	function callBack(response, row) {
		var id = response.getValue('id', row);
		var name = response.getValue('name', row);
		$("#selectRule").html("<option value='" + id + "' selected=\"selected\" >" + name + "</option>");
	}
	
	function downRescouse(){
		$("#membersIntgra").empty();
		var shopId="";
		if($("#shopIsChoosed").is(":checked")){	
			shopId=getHtmlString($("#shopID").val());
		}
		var custName = $('#custName').val();
		var ruleId = $('#selectRule').val();
		var startDate = $('#startDate').val();
		var endDate = $('#endDate').val();
		var paid = $('#paid').val();
		var memberCardNo = $("#memberCardNo").val()
		var mp = $("#mp").val();
		var param={
				shopId : shopId,
				startDate : startDate,
				endDate : endDate,
				paid : paid,
				ruleId :ruleId,
				custName : custName,
				memberCardNo : memberCardNo,
				mp:mp
			}
		window.location.href='../memberIntgra/exports/csv?'+$.param(param);
	}
	
</script>
</head>
<body>
	<div id="yinying"></div>
	<div id="yinying1"></div>
	<!-- 页面列表 -->
	<div class="container" id="container">
		<div class="container_R fr" id="IntgraSelect">
			<div class="place">会员积分</div>
			<div class="member_search">
				<p>
					<span> <input type="checkbox" id="shopIsChoosed"
						style="width: auto; height: auto; border: none;"> 店面：
					</span><select id="shopID"  class="shopName" onclick="openShopListPanel(this)" style="height: 20px;width: 150px;"></select>
					<span>起始日期：</span> <input type="text" readonly
						class="doubledate ipticon" id="startDate" /> <span>截止日期：</span> <input
						type="text" readonly class="doubledate1 ipticon" id="endDate" />
				</p>
				<p>
					<span>会员卡号：</span> <input type="text" id="memberCardNo" class="absoluteTxt" />
					<span>手机：</span> <input type="text" id="mp" class="absoluteTxt"/> 
					<span>支付状态：</span><select
						id="paid">
						<option value="">所有</option>
						<option value="0">未处理</option>
						<option value="1">已处理</option>
						</select>
				</p>
				<p>
					<span>会员姓名：</span> <input type="text" id="custName" class="absoluteTxt" />
					<span>规则名称：</span> <select id="selectRule" onclick="selectIntgraRule()"></select>
					<input type="button" value="查询" class="btn" onclick="toSearch()">
				</p>
				<!-- 					<span>单据状态：</span> <select id="status">
						<option value="">所有</option>
						<option value="0">未审</option>
						<option value="1">已审</option>
					</select>  -->

			</div>
			<table width="100%" class="member_list" cellpadding="0"
				cellspacing="1" border="0" id="memberList">
				<caption>
					<strong>会员积分列表 <span  id="sup">共0条</span></strong><a href="javascript:void(0)" onclick="downRescouse()">导出数据</a>
				</caption>
				<thead>
					<tr>
						<th>店面</th>
						<th>单据号</th>
						<th>办理时间</th>
						<th>会员卡号</th>
						<th>会员姓名</th>
						<th>电话</th>
						<th>规则类型</th>
						<th>积分类型</th>
						<th>积分</th>
						<th>经办人</th>
						<th>状态</th>
					</tr>
				</thead>
				<tbody id="membersIntgra">

				</tbody>
			</table>
			<div id="pager" style="float: right;"></div>
			<div id="sum" style="float: left;"></div>
		</div>
		<div class="fc"></div>
	</div>

	<!-- InstanceEndEditable -->
	<script type="text/javascript" src="../js/header.js"></script>
	<script type="text/javascript" src="../js/left.js"></script>
	<script type="text/javascript" src="../js/footer.js"></script>
	<script type="text/javascript">
	clearThis("absoluteTxt");
	</script>
</body>
<!-- InstanceEnd -->
</html>
